package com.ywu.application.standard.component.api;

import com.ywu.common.result.CommonResult;
import com.ywu.application.standard.component.dto.ComponentDto;
import com.ywu.application.standard.component.entity.ComponentEntity;
import com.ywu.application.standard.component.service.ComponentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ComponentApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/3/23 16:54
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/component")
public class ComponentApi {
    @Autowired
    private ComponentService componentService;

    /**
    * @Author GroundDemo
    * @Description 查询组件列表
    * @Date 17:17 2024/3/23
    * @Param [componentDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/component.query.list")
    public CommonResult<Object> queryComponents(@RequestBody ComponentDto componentDto) {
        return componentService.queryComponents(componentDto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询组件数据，避免全量查询所有数据
    * @Date 14:48 2024/9/26
    * @Param [componentDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/component.query.list.with.no.content")
    public CommonResult<Object> queryComponentsWithNoContent(@RequestBody ComponentDto componentDto) {
        return componentService.queryComponentsWithNoContent(componentDto);
    }

    /**
    * @Author GroundDemo
    * @Description 添加组件
    * @Date 18:51 2024/3/24
    * @Param [componentDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/component.add.info")
    public CommonResult<Object> addComponent(@RequestBody ComponentDto componentDto) {
        return componentService.addComponent(componentDto);
    }

    /**
    * @Author GroundDemo
    * @Description 修改组件
    * @Date 21:29 2024/3/27
    * @Param [componentDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/component.update.info")
    public CommonResult<Object> updateComponent(@RequestBody ComponentDto componentDto) {
        return componentService.updateComponent(componentDto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除组件
    * @Date 21:30 2024/3/27
    * @Param [componentDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/component.delete.info")
    public CommonResult<Object> deleteComponent(@RequestBody ComponentDto componentDto) {
        return componentService.deleteComponent(componentDto);
    }

    /**
     * @Author GroundDemo
     * @Description 查询图标组件列表 - 不进行租户隔离
     * @Date 17:17 2024/3/23
     * @Param [componentDto]
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/component.icon.query.list")
    public CommonResult<Object> queryIconComponents(@RequestBody ComponentDto componentDto) {
        return componentService.queryIconComponents(componentDto);
    }

    /**
     * @Author GroundDemo
     * @Description 根据组件ID批量查询组件详情
     * @Date 17:17 2024/3/23
     * @Param [componentDto]
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/component.batch.query.by.ids.spi")
    public CommonResult<List<ComponentEntity>> batchQueryByIds(@RequestBody List<Integer> ids) {
        return componentService.batchQueryByIds(ids);
    }

    /**
    * @Author GroundDemo
    * @Description 根据组件ID批量查询组件详情 - 不携带组件数据
    * @Date 11:43 2024/9/27
    * @Param [ids]
    * @return com.ywu.common.result.CommonResult<java.util.List<com.ywu.component.standard.entity.ComponentEntity>>
    **/
    @PostMapping("/component.batch.query.by.ids.spi.with.no.content")
    public CommonResult<List<ComponentEntity>> batchQueryByIdsWithNoContent(@RequestBody List<Integer> ids) {
        return componentService.batchQueryByIdsWithNoContent(ids);
    }
}
